package com.example.admin.goodnews.adapter;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;

import com.bumptech.glide.Glide;
import com.bumptech.glide.load.engine.DiskCacheStrategy;
import com.example.admin.goodnews.R;

import java.util.List;

public class PhotoWallAdapter extends BaseAdapter {
    private Context context;
    private List<String> gallerylist;

    public PhotoWallAdapter(Context context, List<String> gallerylist) {
        this.context = context;
        this.gallerylist = gallerylist;
    }

    @Override
    public int getCount() {
        return gallerylist.size();
    }

    @Override
    public Object getItem(int position) {
        return gallerylist.get(position);
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        ViewHolder holder = null;
        if (convertView == null) {
            convertView = LayoutInflater.from(context).inflate(R.layout.item_gridview_imageview, null);
            holder = new ViewHolder();
            holder.iv_gridview_item = (ImageView) convertView.findViewById(R.id.iv_gridview_item);
            convertView.setTag(holder);
        } else {
            holder = (ViewHolder) convertView.getTag();
        }
        Glide.with(context).load(gallerylist.get(position)).diskCacheStrategy(DiskCacheStrategy.SOURCE).into(holder.iv_gridview_item);
        return convertView;
    }

    public class ViewHolder {
        private ImageView iv_gridview_item;
    }

}
